<template>
  <div>
    <div>
      <div class="footer">
        <div class="left">剩余{{ count }}个</div>
        <div class="mid">
          <div
            class="state-btn"
            @click="stateChange('all')"
            :class="{ active: currentItem === 'all' }"
          >
            完成
          </div>
          <div
            class="state-btn"
            @click="stateChange('incomplete')"
            :class="{ active: currentItem === 'incomplete' }"
          >
            未完成
          </div>
          <div
            class="state-btn"
            @click="stateChange('complete')"
            :class="{ active: currentItem === 'complete' }"
          >
            已完成
          </div>
        </div>
        <div class="right">
          <span v-if="removeShow" @click="removeComplete">清除已完成</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentItem: "all",
    };
  },
  props: {
    list: {
      type: Array,
      required: true,
    },
  },
  computed: {
    removeShow(){
      return this.list.some(e=>e.isDone)
    },
    count() {
      return this.list.filter((e) => !e.isDone).length;
    },
  },
  methods: {
    removeComplete(){
      this.$emit('removeComplete')
    },
    stateChange(name) {
      this.currentItem = name;
      this.$emit('stateChange',name)
    },
  },
};
</script>

<style lang='less' scoped>
.footer {
  height: 50px;
  padding: 5px;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 0 5px #cfcfcc;
  .mid {
    display: flex;
    .state-btn {
      cursor: pointer;
      padding: 5px;
      margin-right: 20px;
      &:last-child {
        margin: 0;
      }
      &.active {
        border: 2px solid orchid;
      }
    }
  }
  .right {
    cursor: pointer;
  }
}
</style>